package com.D5Power.Stuff
{
	import com.D5Power.Objects.GameObject;
	import com.D5Power.utils.XYArray;
	
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	/**
	 * Hp/Sp 条
	 */ 
	public class HSpbar extends CharacterStuff
	{
		
		public function HSpbar(target:GameObject,attName:String,attMaxName:String,resource:BitmapData,pos:XYArray=null)
		{
			
			super(target,resource,attName,attMaxName,pos);
		}
		
		/**
		 * 渲染
		 * @param		buffer		缓冲区
		 * @param		p			角色的标准渲染坐标
		 */ 
		override public function render(buffer:BitmapData,p:Point):void
		{
			if(buffer==null) return;
			if(_resource==null) return;
			
			buffer.lock();
			buffer.copyPixels(_resource,numRect,new Point(p.x+_pos.x,p.y+_pos.y));
			buffer.copyPixels(_resource,lineRect,new Point(p.x+_pos.x,p.y+_pos.y),_resource,new Point(),true);
			buffer.unlock();
		}
		
		/**
		 * 获取线框所在矩形
		 */ 
		protected function get lineRect():Rectangle
		{
			return new Rectangle(0,0,_resource.width,int(_resource.height*0.5));
		}
		
		/**
		 * 获取数据所在矩形
		 */ 
		protected function get numRect():Rectangle
		{
			return new Rectangle(0,int(_resource.height*0.5),int(_resource.width*_target[_attName]/_target[_attMaxName]),int(_resource.height*0.5));
		}
	}
}